// To parse this JSON data, do
//
//     final clients = clientsFromJson(jsonString);

import 'dart:convert';
import 'package:flutter_chat_types/flutter_chat_types.dart' as types;

List<Clients> clientsFromJson(String str) =>
    List<Clients>.from(json.decode(str).map((x) => Clients.fromJson(x)));

String clientsToJson(List<Clients> data) =>
    json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

class Clients {
  String id;
  String sendId;
  String sendNickname;
  String sendHeadPortrait;
  String updatedAt;
  int unread;
  String latestText;

  Clients(
      {required this.id,
      required this.sendId,
      required this.sendNickname,
      required this.sendHeadPortrait,
      required this.updatedAt,
      this.latestText = '',
      this.unread = 0});

  factory Clients.fromJson(Map<String, dynamic> json) {
    return Clients(
      id: json['id'],
      sendId: json["send_id"],
      sendNickname: json["send_nickname"],
      sendHeadPortrait: json["send_head_portrait"],
      unread: int.parse(json["receiver_num"]),
      updatedAt: json['updated_at'],
      latestText: json['content'] != ''
          ? (json['content'].startsWith("https://") ? '[图片]' : json['content'])
          : '',
      // unread: int.parse(json['send_num']),
    );
  }

  Map<String, dynamic> toJson() => {
        "send_id": sendId,
        "send_nickname": sendNickname,
        "send_head_portrait": sendHeadPortrait,
      };
}
